//
//  EveryDayVC.m
//  NJUSTHelper
//
//  Created by 郑越辉 on 2017/9/21.
//  Copyright © 2017年 njust. All rights reserved.
//

#import "EveryDayVC.h"
#import "SectionCell.h"
#import "Define.h"
///一天课的大节数
#define SECTION_COUNT 5
@interface EveryDayVC ()  <UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, strong) NSMutableArray *todayScheduleArray;
@end

@implementation EveryDayVC
#pragma mark setter
-(void)setShowDate:(NSDate *)showDate{
    _showDate = showDate;

    ///加1表示周次
    self.currentWeekNum = [[NSDate getFirstDay] compsWeekToDate:showDate] + 1;
    self.todayScheduleArray = [ScheduleDBService getScheduleByWeekDay:[showDate getWeekIndex] UserId:AccountInfo.userId];
}
-(void)setTodayScheduleArray:(NSMutableArray *)todayScheduleArray{
    _todayScheduleArray = todayScheduleArray;
    [self.scheduleTable reloadData];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    [self.scheduleTable registerNib:[UINib nibWithNibName:@"SectionCell" bundle:nil] forCellReuseIdentifier:@"SectionCellIdentifier"];
    self.view.backgroundColor = [UIColor blueColor];
    
}
-(void) reloadTableDate{
    self.todayScheduleArray = [ScheduleDBService getScheduleByWeekDay:[self.showDate getWeekIndex] UserId:AccountInfo.userId];
//    [self.scheduleTable reloadData];
}

#pragma mark - TableViewDelegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return SECTION_COUNT;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if(IS_IPHONE5){
        return 97;
    }
    return self.scheduleTable.frame.size.height/SECTION_COUNT;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    SectionCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SectionCellIdentifier" forIndexPath:indexPath];
    NSMutableArray *sectionSchedulArray = [NSMutableArray array];
    if(self.todayScheduleArray){
        for (ScheduleModel *sechedule in self.todayScheduleArray) {
            if(sechedule.sectionNum == indexPath.row){
                [sectionSchedulArray addObject:sechedule];
            }
        }
    }
    ///显示上课时间
    cell.sectionNum = indexPath.row;
    ///用以区分是否本周课程
    cell.weekNum = self.currentWeekNum;
    ///要先设置好当前周次
    cell.sectionSchedulleArray = sectionSchedulArray;
    return cell;
}



@end
